/*     */ package com.zimbra.cs.index;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import java.io.IOException;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ final class MsgQueryResults
/*     */   extends ZimbraQueryResultsImpl
/*     */ {
/*     */   private final ZimbraQueryResults results;
/*  36 */   private ZimbraHit nextHit = null;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  43 */   private final Set<Integer> mSeenMsgs = new HashSet();
/*     */   
/*     */   MsgQueryResults(ZimbraQueryResults topLevelQueryOperation, Set<MailItem.Type> types, SortBy sort, SearchParams.Fetch fetch)
/*     */   {
/*  47 */     super(types, sort, fetch);
/*  48 */     this.results = topLevelQueryOperation;
/*     */   }
/*     */   
/*     */   public long getCursorOffset()
/*     */   {
/*  53 */     return this.results.getCursorOffset();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private ZimbraHit internalGetNextHit()
/*     */     throws ServiceException
/*     */   {
/*  64 */     while (this.results.hasNext()) {
/*  65 */       ZimbraHit hit = this.results.getNext();
/*     */       
/*     */       MessageHit msgHit;
/*  68 */       if ((hit instanceof MessageHit)) {
/*  69 */         msgHit = (MessageHit)hit; } else { MessageHit msgHit;
/*  70 */         if ((hit instanceof MessagePartHit)) {
/*  71 */           msgHit = ((MessagePartHit)hit).getMessageResult();
/*  72 */         } else { if ((hit instanceof ConversationHit)) {
/*  73 */             throw new UnsupportedOperationException();
/*     */           }
/*     */           
/*     */ 
/*  77 */           return hit;
/*     */         } }
/*     */       MessageHit msgHit;
/*  80 */       int iid = msgHit.getItemId();
/*  81 */       if (this.mSeenMsgs.add(Integer.valueOf(iid)))
/*     */       {
/*  83 */         while (this.results.hasNext()) {
/*  84 */           ZimbraHit next = this.results.peekNext();
/*  85 */           if ((!next.isLocal()) || (iid != next.getItemId())) break;
/*  86 */           this.results.getNext();
/*  87 */           if ((next instanceof MessagePartHit)) {
/*  88 */             msgHit.addPart((MessagePartHit)next);
/*     */           }
/*     */         }
/*     */         
/*     */ 
/*     */ 
/*  94 */         return msgHit;
/*     */       }
/*     */     }
/*  97 */     return null;
/*     */   }
/*     */   
/*     */   private boolean bufferNextHit() throws ServiceException {
/* 101 */     if (this.nextHit == null) {
/* 102 */       this.nextHit = internalGetNextHit();
/*     */     }
/* 104 */     return this.nextHit != null;
/*     */   }
/*     */   
/*     */   public void resetIterator() throws ServiceException
/*     */   {
/* 109 */     this.mSeenMsgs.clear();
/* 110 */     this.results.resetIterator();
/*     */   }
/*     */   
/*     */   public ZimbraHit getNext() throws ServiceException
/*     */   {
/* 115 */     bufferNextHit();
/* 116 */     ZimbraHit toRet = this.nextHit;
/* 117 */     assert ((this.nextHit == null) || ((!(this.nextHit instanceof MessagePartHit)) && (!(this.nextHit instanceof ConversationHit))));
/* 118 */     this.nextHit = null;
/* 119 */     return toRet;
/*     */   }
/*     */   
/*     */   public ZimbraHit peekNext() throws ServiceException
/*     */   {
/* 124 */     bufferNextHit();
/* 125 */     assert ((this.nextHit == null) || ((!(this.nextHit instanceof MessagePartHit)) && (!(this.nextHit instanceof ConversationHit))));
/* 126 */     return this.nextHit;
/*     */   }
/*     */   
/*     */   public void close() throws IOException
/*     */   {
/* 131 */     this.results.close();
/*     */   }
/*     */   
/*     */   public ZimbraHit skipToHit(int hitNo) throws ServiceException
/*     */   {
/* 136 */     if (hitNo > 0) {
/* 137 */       this.results.skipToHit(hitNo - 1);
/*     */     } else {
/* 139 */       resetIterator();
/*     */     }
/* 141 */     return getNext();
/*     */   }
/*     */   
/*     */   public List<QueryInfo> getResultInfo()
/*     */   {
/* 146 */     return this.results.getResultInfo();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/index/MsgQueryResults.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */